import { scrollMixin } from 'utils/mixin';
import {
  Toast
} from 'vant';
export default {
  mixins: [scrollMixin], // 加载更多
  data() {
    return {
      agentLevel: '', //代理商等级
      username: '', //会员昵称
      avatar_image: '', //会员头像
      pagingChoose: '',//分页筛选参数
      earningsPrice: ["total_reward", "already_settled", "not_settled"],
      orderPage: 1, //订单列表当前页
      page: 1,//时间列表当前页
      earnings: [{
        price: '',
        name: '累计获得奖励'
      }, {
        price: '',
        name: '已结算金额'
      }, {
        price: '',
        name: '未结算金额'
      }],
      activeName: '', //已选中的标签页
      orderSelection: [{
        title: '全部',
        name: "all"
      }, {
        title: '已结算',
        name: 1
      }, {
        title: '未结算',
        name: 0
      }], //订单筛选
      activeLabelName: '', //折叠面板
      listOfTime: [], //时间列表
      orderList: [], //订单列表
      orderLastPage: false,//订单是否最后一页
      labelStatus: 'unselected' //标签状态
    };
  },
  activated() { },
  created() {

  },
  mounted() {
    this.getData()
  },
  methods: {
    //获取数据
    getData(type) {
      let json = {
        page: this.page
      }
      if (type != "all" && type != undefined) {
        json["settlement_status"] = type
      }
      $http.post('plugin.difference-reward.frontend.reward-log.get-reward-list', json).then((res) => {
        if (res.result === 1) {
          let { list, member_info, reward_summarize } = res.data;
          this.listOfTimePage = false
          this.agentLevel = member_info.level_name || null;
          this.username = member_info.username
          this.avatar_image = member_info.avatar_image
          this.earnings.forEach((item, index) => {
            this.earnings[index].price = reward_summarize[this.earningsPrice[index]]
          })
          this.listOfTime = list
        } else {
          this.$dialog.alert({
            message: res.msg
          });
        }
      },
        function (response) {
          // error callback
        });
    },

    //获取月份展开订单数据
    getOrderList(month, type) {
      if (typeof (month) == "number") {
        month = this.listOfTime[month].sub_month_str.replace("-","")
      }
      if (type != "more") {
        this.orderPage = 1
      }
      if (!month) {
        return
      }
      let json = {
        month_str: month,
        page: this.orderPage
      }
      if (this.labelStatus != "all" && this.labelStatus != 'unselected') {
        json["settlement_status"] = this.labelStatus
      }
      $http.post('plugin.difference-reward.frontend.reward-log.get-reward-list-to-month', json).then((res) => {
        if (res.result === 1) {
          let data = res.data
          this.orderLastPage = false
          if (data.list.current_page >= data.list.last_page) { //判断订单列表是否为最后一页
            this.orderLastPage = true
          }
          if (type == "more") { //如果是查看更多数组值累加
            this.orderList = [...this.orderList, ...data.list.data]
          } else {
            this.orderList = data.list.data
          }
          this.pagingChoose = data.list
        } else {
          this.$dialog.alert({
            message: res.msg
          });
        }
      },
        function (response) {
          // error callback
        });
    },

    //查看更多
    readMore(month) {
      this.orderPage++
      this.getOrderList(month, "more")
    },
    clickChange(e) { //标签改变
      this.getData(e)
      this.labelStatus = e
      this.activeLabelName = ''
    }
  },
};
